# -*- coding: utf-8 -*-
#
#	Copyright (C) 2011 by Igor E. Novikov
#	
#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#	
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#	
#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>. 

from PyQt4 import Qt, QtGui, QtCore

from menubar import AppMenuBar
from maintoolbar import AppMainBar
from color import qt_middle_color

class MainWindow(QtGui.QMainWindow):
	"""
	The class represents main application window.
	
	app - Formats Explorer Application class instance 
	"""

	mdiArea = None
	app = None

	def __init__(self, app):

		super(MainWindow, self).__init__()

		self.app = app
		self.set_title()
		self.setWindowIcon(app.generic_icons['FE'])


		self.mdiArea = QtGui.QMdiArea()
		self.setCentralWidget(self.mdiArea)
		self.mdiArea.setDocumentMode(True)
		clr = qt_middle_color(self.palette().text().color(), self.palette().background().color(), 0.4)
		self.mdiArea.setBackground(Qt.QBrush(clr))

		self.menubar = AppMenuBar(self)
		self.setMenuBar(self.menubar)

		self.maintoolbar = AppMainBar(self)
		self.addToolBar(self.maintoolbar)

		self.setMinimumSize(self.app.config.mw_min_width, self.app.config.mw_min_height)
		self.resize(self.app.config.mw_width, self.app.config.mw_height)

		if self.app.config.mw_maximized:
			self.setWindowState(Qt.Qt.WindowMaximized)

		screen = QtGui.QDesktopWidget().screenGeometry()
		size = self.geometry()
		self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 3)

	def closeEvent(self, event):
		self.app.app_exit()

	def set_title(self):
		app_name = self.app.appdata.app_name
		self.setWindowTitle(app_name)
